package org.NooLab.glue.net.sockets.udp;

import java.io.InputStream;
import java.util.Observable;
import java.util.Observer;

import org.NooLab.glue.components.DataReceiverIntf;
import org.NooLab.glue.components.pkg.DataDeliveryPackage;
import org.NooLab.glue.components.pkg.DataDeliveryPackageIntf;
import org.NooLab.glue.net.BoxDataIntf;
import org.NooLab.glue.net.DataSlot;
import org.NooLab.glue.net.TransportBoxIntf;


import org.NooLab.utilities.files.DFutils;
import org.NooLab.utilities.logging.PrintLog;

 
 

public class UdpBox extends Observable implements   // 
													TransportBoxIntf,
													// returns data object
													GlueUdpHandlerIntf {

	private UdpDataSender   udpSender ;
	private UdpDataReceiver udpReceiver ;
	
	// 
	private UdpBoxPropertiesIntf udpBoxProperties;
	
	BoxDataIntf boxData ;
	
	int listenport ;
	int ctrlport;
	Observer observer;
	String description;
	
	
	private boolean selfTestOn = false;
	private String selftestCompareStr="";
	
	protected DFutils fileutil = new DFutils() ;
	private PrintLog out = new PrintLog(2,false);
	
	
	public UdpBox( int listenport , int ctrlport, Observer observer, String description ){
		
		 this.listenport = listenport ;
		 this.ctrlport = ctrlport ;
		 this.observer = observer ;
		 this.description = description ;
	}
	
	public void initialize( UdpBoxPropertiesIntf props){
		
		if (props.getLoggingLevelAlias()>=2){
			out = new PrintLog(2,true);
		}
		
		/*
		
				ftpServer = new FtpServerApaj( props.getListeningPorts()[0], 
									   (GlueFtpletHandlerIntf)(props.getFtpDataEndpoint()), 
									   boxUser,
									   props.getLoggingLevelAlias() ) ;
		 
		
		out.print(2, "creating instance of ftpClient ... ") ;
		
		ftpClient = new FtpClientApaj( boxUser, props.getLoggingLevelAlias() );
		ftpClient.setup() ;
		
		*/
		// in full-duplex mode there only the receiver is permanent
		
		// udpReceiver = createReceiver() 
		
	}
	
	
	public UdpBoxPropertiesIntf createUdpBoxProperties(){
		
		DataDeliveryPackage udpDeliveryPkg = null;
		
		udpBoxProperties = new UdpBoxProperties();
		
		udpDeliveryPkg = new DataDeliveryPackage();
		
		udpBoxProperties.setUdpDeliveryPackage(udpDeliveryPkg)  ; 
			
			
		return (UdpBoxPropertiesIntf)udpBoxProperties ;
	}
	
	/*
	public udpReceiver = createReceiver()
	udpReceiver = new UdpDataReceiver( int listenport , int ctrlport, Observer observer, String description );

	*/
	
	
	public DataReceiverIntf getReceiver( ){
		return udpReceiver;
	}
	
	public DataReceiverIntf createReceiver( ){
		
		
		udpReceiver = new UdpDataReceiver( listenport , ctrlport, observer, description );
		
		return udpReceiver;
	}
	
	
	public DataReceiverIntf createReceiver( int listenport , int ctrlport, Observer observer, String description ){
		DataReceiverIntf receiver;
		
		receiver = new UdpDataReceiver( listenport , ctrlport, observer, description );
		
		return receiver;
	}
	                                                                                              
	
	
	public void selfTest(){
		
		DataDeliveryPackageIntf testpkg ;
		InputStream istream = null ;
		String outstr = "ABC" ,str;
		
	}

	
	// callback methods to receive the data via the interface "GlueUdpHandlerIntf"
	@Override
	public void getUdpMessageStr(String msg) {
		 
		
	}

	@Override
	public void getUdpMessageObj(DataSlot dataslot) {
		 
		
	}
	
	
	
	
	
}
